package com.yc.cloud.portal.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.portal.request.MediaBasicInfoParam;
import com.yc.cloud.portal.request.MediaCaptureParam;
import com.yc.cloud.portal.request.MediaLocationInfoParam;
import com.yc.cloud.portal.request.MediaOcrInfoParam;
import com.yc.cloud.portal.service.MediaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/media")
@Api(tags = "慧视接口模块")
@Slf4j
public class MediaController {

    private final MediaService mediaServiceService;

    public MediaController(MediaService mediaServiceService) {
        this.mediaServiceService = mediaServiceService;
    }

    @PostMapping("/basicInfo")
    @ApiOperation(value = "AR 眼镜发送设备状态给慧视平台", notes = "将眼镜在线状态上报给慧视平台")
    public ResponseResult<String> basicInfo(@RequestBody @Validated MediaBasicInfoParam param) {
        log.info("AR 眼镜发送设备状态接口, param={}", param);
        return mediaServiceService.basicInfo(param);
    }

    @PostMapping("/capture")
    @ApiOperation(value = "推送图片信息给慧视平台", notes = "将抓拍的照片信息上报给慧视平台")
    public ResponseResult<String> capture(@RequestBody @Validated MediaCaptureParam param) {
        //这里我为了不想输出一长串的图片信息，所以把图片信息设置为空
        val tempMediaCaptureParam = new MediaCaptureParam();
        BeanUtils.copyProperties(param, tempMediaCaptureParam);
        tempMediaCaptureParam.setPicString("");
        log.info("推送图片信息接口, param={}", tempMediaCaptureParam);
        return mediaServiceService.capture(param, null);
    }

    @PostMapping("/ocr/info")
    @ApiOperation(value = "OCR识别结果给慧视平台", notes = "提取图片中的文字信息")
    public ResponseResult<String> ocrInfo(@RequestBody @Validated MediaOcrInfoParam param) {
        log.info("ocr识别结果接口, param={}", param);
        return mediaServiceService.ocrInfo(param);
    }

    @PostMapping("/location/info")
    @ApiOperation(value = "推送设备定位信息给慧视平台", notes = "将设备的定位信息上报给慧视平台")
    public ResponseResult<String> locationInfo(@RequestBody @Validated MediaLocationInfoParam param) {
        log.info("推送设备定位信息接口, param={}", param);
        return mediaServiceService.locationInfo(param);
    }
}
